<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
	content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>后台代码生成</title>
<link rel="stylesheet" href="${ctxPath}/layui/css/layui.css">
<script src="${ctxPath}/libs/jquery.min.js"></script>
<script src="${ctxPath}/libs/jquery.slimscroll.min.js"></script>
<script src="${ctxPath}/libs/pace.min.js"></script>
<script src="${ctxPath}/layui/layui.js"></script>
<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
<!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<style type="text/css">
</style>
</head>
<body>
	<div class="layui-container">
		<table class="layui-hide" id="test" lay-filter="test"></table>
	</div>
<script type="text/html" id="toolbarDemo">
	<div class="layui-inline">
		<label class="layui-form-label">表名</label>
		<div class="layui-input-inline" style="width: 180px;">
			<input type="text" id="key" name="key" class="layui-input" placeholder="表名" id="key">
		</div>
	</div>
	<button class="layui-btn layui-btn-sm" lay-event="search">查询</button>
    <button class="layui-btn layui-btn-sm" lay-event="edit">编辑</button>
    <button class="layui-btn layui-btn-sm" lay-event="refresh">刷新</button>
</script>
<script>
    //JavaScript代码区域
    layui.use('table', function(){
	 	var table = layui.table;
	 	
		var codeTable = table.render({
			elem: '#test',
			url:'${ctxPath}/code/gen/list',
			toolbar: '#toolbarDemo',
			page: true,
			height: 'full-30',
			cols: [[
				{type:'checkbox', fixed: 'left'},
				{field:'name', width:200, title: '类名'},
				{field:'tableName', width:200, title: '表名'},
				{field:'comment', width:250, title: '注释'}
			]],
			parseData: function(res){
				return {
			      "code": res.data.code, //解析接口状态
			      "msg": res.data.message, //解析提示文本
			      "count": res.data.count, //解析数据长度
			      "data": res.data.data //解析数据列表
			    };
			}
		});
	 	
			//监听表格复选框选择
		table.on('toolbar(test)', function(obj){
			var checkStatus = table.checkStatus(obj.config.id); //获取选中行状态
			switch(obj.event){
				case 'search':
					var key = $("#key").val();
					codeTable.reload({
						page: {
							curr: 1 //重新从第 1 页开始
						},
						where: {
							key: key
						}
					});
					$("#key").val(key);
		      	break;
		      	case 'edit':
			        var data = checkStatus.data;
			        var index = layer.open({
					  	type: 2,
					  	title: '代码生成',
					  	shadeClose: true,
					  	content: '${ctxPath}/code/gen/detail?tableName='+data[0].tableName
					});
					layer.full(index);
		      	break;
		      	case 'refresh':
			        $.get("${ctxPath}/code/gen/refresh",function(res){
			        	codeTable.reload();
			        });
		      	break;
			};
		});
	});
</script>
</body>
</html>